import {
	ajax as commonAjax,
	getUserInfo
} from '@/common/common.js'
import {
	bpmUrl
} from "@/common/config.js"
let user = getUserInfo()
let paramas = {
	headersMap: {
		sysid: "bpm",
		syspwd: "pass",
		userid: user.bpmUid
	}
}

// js封装所需
function ajax(opt) {
	return new Promise((resolve, reject) => {
		let complete = (complete) => {
			if (opt.complete) {
				opt.complete(complete)
			}
			resolve(complete)
		}
		try {
			commonAjax({ ...opt,
				complete
			})
		} catch (e) {
			reject()
		}
	})
}
//初始赋值
function formonload(list, formData, bussiness) {
	let currentNodeid = bussiness.currentNodeid
	let WF_DocStatus = bussiness.docStatus
	let isFirstNodeFlag = bussiness.isFirstNodeFlag || ''
	// todo: 获取邮件邮箱分组
	ajax({
		url: '/om/r?wf_num=D_hra_J002&wf_gridnum=V_hra_G003&rdm=0.5160284205597288',
		method: 'GET',
		// data: {
		// 	...paramas,			
		// 	paramasMap: {
		// 		// staff_no: val,
		// 	},
		// 	// url: 'http://bpm.moyun.tech/om/r?wf_num=D_hra_J002&wf_gridnum=V_hra_G003&rdm=0.5160284205597288'
		// },
		success: res => {
			list.forEach(item => {
				if (['emailGroupForm'].indexOf(item.name) != -1) {
					// item.optiona.data = res
				}
			})
		}
	})
	if (currentNodeid == 'T10002') {
		if (WF_DocStatus == 'ARC') {
			list.forEach(item => {
				if (['Update_date'].indexOf(item.name) != -1) {
					item.hidden = '0'
				}
			})
		} else {
			list.forEach(item => {
				if (['Update_date'].indexOf(item.name) != -1) {
					item.hidden = '1'
				}
			})
		}
	} else {
		list.forEach(item => {
			if (['Update_date'].indexOf(item.name) != -1) {
				item.hidden = '0'
			}
		})
	}
	// todo: 提示显示/隐藏
	if (currentNodeid == 'T10108') {
		list.forEach(item => {
			if (['itwrite'].indexOf(item.name) != -1) {
				item.hidden = '0'
			}
			if (['itdevice'].indexOf(item.name) != -1) {
				item.hidden = '1'
			}
			if (['fin_print'].indexOf(item.name) != -1) {
				item.hidden = '0'
			}
			if (['emailGroupForm'].indexOf(item.name) != -1) {
				item.rules = '[{"required":true,"emptyMsg":"必填"}]'
			}
		})
	} else if (currentNodeid == 'T10167' || currentNodeid == 'T10166' || currentNodeid == 'T10133' || currentNodeid ==
		'T10134' || currentNodeid == 'T10135') {
		list.forEach(item => {
			if (['fin_print'].indexOf(item.name) != -1) {
				item.hidden = '1'
			}
			if (['itdevice'].indexOf(item.name) != -1) {
				item.hidden = '1'
			}
			if (['emailLinkmanBtn'].indexOf(item.name) != -1) {
				item.hidden = '1'
			}
		})
	} else {
		// todo: isFirstNodeFlag判断
		if (isFirstNodeFlag == 'true') { //首环节
			list.forEach(item => {
				if (['itwrite'].indexOf(item.name) != -1) {
					item.hidden = '1'
				}
				if (['fin_print'].indexOf(item.name) != -1) {
					item.hidden = '1'
				}
				if (['itdevice'].indexOf(item.name) != -1) {
					item.hidden = '1'
				}
			})
		} else {
			list.forEach(item => {
				if (['itwrite'].indexOf(item.name) != -1) {
					item.hidden = '０'
				}
				if (['emailLinkmanBtn'].indexOf(item.name) != -1) {
					item.hidden = '1'
				}
				if (['fin_print'].indexOf(item.name) != -1) {
					item.hidden = '０'
				}
				if (['itdevice'].indexOf(item.name) != -1) {
					item.hidden = '０'
				}
			})
		}
	}
	return list
}
// todo: 下载表格
function downloadExcep() {
	// window.open("oumeng/HR_M00011_CN_V1.doc");
}

function downloadExcep2() {
	// window.open("oumeng/HR_M00012_CN_V3.xlsx");
}

function downloadExcep3() {
	// window.open("oumeng/staff_legal.docx");
}

function formonsubmit(list, formData, bussiness) {
	let flag = true
	let currentNodeid = bussiness.currentNodeid
	// todo: isFirstNodeFlag判断
	if (currentNodeid == 'T10108') {
		let nb_use_type = formData.nb_use_type
		let dc_use_type = formData.dc_use_type
		let nb_device_type = formData.nb_device_type
		let dc_device_type = formData.dc_device_type
		// 直接领导填写环节
		if (nb_use_type != "" && dc_use_type != "") {
			uni.showToast({
				title: "您好:台式机和笔记本不能同时选择，只能选择其中一类",
				icon: 'none'
			})
			return false;
		}
		if (nb_device_type != "" && dc_device_type != "") {
			uni.showToast({
				title: "您好:台式机和笔记本不能同时选择，只能选择其中一类",
				icon: 'none'
			})
			return false;
		}
		if (nb_use_type != "" && nb_device_type == "") {
			uni.showToast({
				title: "您好:请选择笔记本电脑分类",
				icon: 'none'
			})
			return false;
		} else if (dc_use_type != "" && dc_device_type == "") {
			uni.showToast({
				title: "您好:请选择台式机电脑分类",
				icon: 'none'
			})
			return false;
		} else if (nb_use_type == "" && nb_device_type != "") {
			uni.showToast({
				title: "您好:请选择笔记本用途分类",
				icon: 'none'
			})
			return false;
		} else if (dc_use_type == "" && dc_device_type != "") {
			uni.showToast({
				title: "您好:请选择台式机用途分类",
				icon: 'none'
			})
			return false;
		}
	}
	return flag;
}

export default {
	formonload,
	formonsubmit,
	downloadExcep,
	downloadExcep2,
	downloadExcep3,
}
